﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using SelfMadeMillionaire.Core;
using SelfMadeMillionaire.Core.Entities;
using SelfMadeMillionaire.Core.Enums;
using SelfMadeMillionaire.Core.Repositories;
using SelfMadeMillionaire.Core.Services;
using SelfMadeMillionaire.Core.Specifications;

namespace SelfMadeMillionaire.BLL.Services
{
	public class NewsService : INewsService
	{
		private readonly INewsRepository _NewsRepository;

		public NewsService(INewsRepository NewsRepository)
		{
			_NewsRepository = NewsRepository;
		}

		public News Add(News News)
		{
			News.CreatedDate = DateTime.Now;
			News.Status = (byte) StatusType.Active;
			return _NewsRepository.Add(News);
		}

		public News Update(News News)
		{
			return _NewsRepository.Update(News);
		}

		public News Get(int id)
		{
			return _NewsRepository.Get(id);
		}
        
		public IEnumerable<News> GetList(ISearchSpecification<News> specification)
		{
			return _NewsRepository.GetList(specification);
		}

		public void Remove(int id)
		{
			News News = Get(id);
			News.Status = (byte) StatusType.Deleted;
			Update(News);
		}
	}
}